#!/bin/bash

set -e

package_tar_name=$1
package_name=`echo $package_tar_name | sed 's/\(.*\)\.tar\..*/\1/'`
package_name=`echo $package_name | sed 's/-src$//'`

echo "build start: $package_name";

pushd /sources
    tar -xvf $package_tar_name
    chown -R root:root $package_name
    cd $package_name
    ( bash -e /root/projects/lfs/blfs/$package_name.sh 2>&1 | tee /root/projects/lfs/blfs/logs/$package_name.log && exit $PIPESTATUS )
    cd ..
    rm -rf $package_name
popd

echo "build end: $package_name";
